<?php
/**
 * Created by PhpStorm.
 * User: ASUS
 * Date: 2016/12/25
 * Time: 16:53
 */
require './PhpExcel/PHPExcel.class.php';
require './PhpExcel/PHPExcel/IOFactory.php';
$data = array(0=>array('0','1','2','3','4','5','6','7','8'),
    1 =>array('0','1','2','3','4','5','6','7','8'),
    2=>array('0','1','2','3','4','5','6','7','8'));
//function ExcelList($data){
    $excel = new \PHPExcel();
    $excel->createSheet();
    $excel->setActiveSheetIndex();
    $objSheet=$excel->getActiveSheet();
    $excel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('E')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('F')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('I')->setAutoSize(true);
    $excel->getActiveSheet()->getColumnDimension('J')->setAutoSize(true);
    $objSheet->setTitle('商户信息');
    $objSheet->setCellValue("A1","商户号")->setCellValue("B1","商户名称")->setCellValue("C1","手机号")->setCellValue("D1","邮箱")->setCellValue("E1","店铺数")->setCellValue("F1","理发师数量")->setCellValue("G1","短信数量")->setCellValue("H1","商户状态")->setCellValue("I1","备注")->setCellValue("J1","时间");
    $j=2;
    foreach($data as $key=>$val){
        $objSheet->setCellValue("A".$j,$val['0'])->setCellValue("B".$j,$val['1'])
            ->setCellValue("C".$j,$val['2'])->setCellValue("D".$j,$val['3'])
            ->setCellValue("E".$j,$val['4'])->setCellValue("F".$j,$val['5'])
           ->setCellValue("I".$j,$val['7'])
            ->setCellValue("J".$j,$val['8']);
        $j++;
    }
    $objWriter=\PHPExcel_IOFactory::createWriter($excel,'Excel5');//生成excel文件
    //$objWriter->save($dir."/export_1.xls");//保存文件
browser_export('Excel5','商户信息'.date("Y-m-d",time()).'xls');//输出到浏览器
    $objWriter->save("php://output");
//}
function browser_export($type,$filename){
    if($type=="Excel5"){
        header('Content-Type: application/vnd.ms-excel');//告诉浏览器将要输出excel03文件
    }else{
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');//告诉浏览器数据excel07文件
    }
    header('Content-Disposition: attachment;filename="'.$filename.'"');//告诉浏览器将输出文件的名称
    header('Cache-Control: max-age=0');//禁止缓存
}